export default {
  namespaced: true,
  state: {
    //用户信息
    userinfo: sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')) : {},
    //用户私人歌单
    userPrivatePlayList: sessionStorage.getItem('userPrivatePlayList') ? JSON.parse(sessionStorage.getItem('userPrivatePlayList')) : [],
    //用户登录状态
    loginStatus: sessionStorage.getItem('loginStatus') ? (sessionStorage.getItem('loginStatus')) : "false",
    //用户id
    userId: sessionStorage.getItem("userId") ? sessionStorage.getItem("userId") : "",
    //是否签到
    isSign: sessionStorage.getItem('isSign') ? sessionStorage.getItem('isSign') : false
  },
  mutations: {
    // 保存用户信息
    SAVE_USERINFO(state, userinfo) {
      state.userinfo = userinfo
    },
    //保存用户私人歌单
    SAVE_USERPRIVATEPLAYLIST(state, userPrivatePlayList) {
      state.userPrivatePlayList = userPrivatePlayList
    },
    //保存登录状态
    SAVE_LOGINSTATUS(state, loginStatus) {
      state.loginStatus = loginStatus
    },
    //保存用户id
    SAVE_USERID(state, userId) {
      state.userId = userId
    },
    //保存签到状态
    SAVE_ISSIGN(state, isSign) {
      state.isSign = isSign
    }
  },
  actions: {
    // 保存用户信息
    saveUserInfo({
      commit
    }, payload) {
      commit('SAVE_USERINFO', payload)
    },
    //保存用户私人歌单
    savePrivatePlayList({
      commit
    }, payload) {
      commit('SAVE_USERPRIVATEPLAYLIST', payload)
    },
    //保存用户登录状态
    saveLoginStatus({
      commit
    }, payload) {
      commit('SAVE_LOGINSTATUS', payload)
    },
    //保存用户id
    saveUserId({
      commit
    }, payload) {
      commit('SAVE_USERID', payload)
    },
    //保存签到信息
    saveIsSign({
      commit
    }, payload) {
      commit('SAVE_ISSIGN', payload)
    }
  },
  getters: {
    // 保存用户信息
    userinfo: state => {
      return state.userinfo
    },
    //保存用户私人歌单
    userPrivatePlayList: state => {
      return state.userPrivatePlayList
    },
    //保存用户登录状态
    loginStatus: state => {
      return state.loginStatus
    },
    //保存用户id
    userId: state => {
      return state.userId
    },
    isSign: state => {
      return state.isSign
    }
  }
}
